package com.mhl.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import com.mhl.campuscabinet.R;
import com.mhl.client.HttpUtil;
import com.mhl.entity.Comment;

import java.util.List;

public class ProductImageAdapter extends RecyclerView.Adapter<ProductImageAdapter.MyViewHolder>{
    private final List<String> mProImageList;
    private AppCompatActivity activity;

    static class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView productimage;
        public MyViewHolder(View itemView) {
            super(itemView);
            productimage = (ImageView) itemView.findViewById(R.id.productimage);
        }
    }

    //构造方法，传入数据
    public ProductImageAdapter(List<String> list, AppCompatActivity activity){
        this.mProImageList = list;
        this.activity = activity;
    }

    @NonNull
    @Override
    public ProductImageAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder，返回每一项的布局
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_productimage, parent, false);
        return new ProductImageAdapter.MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ProductImageAdapter.MyViewHolder holder, int position) {
        int screenWidth = activity.getResources().getDisplayMetrics().widthPixels;
        int width = screenWidth - 10;
        // 加载图片
        Glide.with(activity).load(mProImageList.get(position))
                .override(width, Target.SIZE_ORIGINAL)
                .fitCenter()
                .into(holder.productimage);
        System.out.println("加载图片");
    }

    @Override
    public int getItemCount() {
        //返回Item总条数
        return mProImageList.size();
    }

}
